<?php

namespace app\api\logic;

use app\common\model\Help;

class HelpLogic
{
    protected Help $model;

    public function __construct()
    {
        $this->model = new Help();
    }

    public function getList(array $param)
    {
        $query = $this->model
            ->field('id,title,content,image,createtime')
            ->where('deletetime',$this->model::DELETE_TIME);
        if ($param['keyword']) {
            $query->where('title','LIKE','%'.trim($param['keyword']).'%');
        }

        return $query->order('id DESC')
            ->paginate([
                'list_rows' => $param['limit'] ?? 10,
                'page' => $param['page']
            ]);
    }

    public function detail(int $id)
    {
        $info = $this->model
            ->field('id,title,content,image,createtime')
            ->where('id',$id)
            ->where('deletetime',$this->model::DELETE_TIME)
            ->find();
        if (!$info) {
            return $this->error('数据不存在');
        }

        return $info;
    }

}